﻿using DevComponents.DotNetBar.Metro;
using PlatForm.Controller;
using PlatForm.DataLayer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PlatForm.Presentation
{
    public partial class frmQC : MetroForm
    {
        private PickingController picking = new PickingController();

        public frmQC()
        {
            InitializeComponent();
            dGVQC.AutoGenerateColumns = false;
        }

        private void Init()
        {
            var lst = picking.GetPick(DateTime.Now.Date);
            dGVQC.DataSource = lst;
        }

        private void frmQC_Load(object sender, EventArgs e)
        {
            Init();
        }
        
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
                    
                    case Keys.Enter:
                   
                    break;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
           
        }

        private void txtORD_No_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                foreach (DataGridViewRow r in dGVQC.Rows)
                {
                    if (r.Cells[0].Value.Equals(txtORD_No.Text.Trim()))
                    {
                        r.Selected = true;
                        break;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        private void btnCheck_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (DataGridViewRow r in dGVQC.Rows)
                {
                    if (r.Cells[1].Value.ToString().Equals(txtORD_No.Text.Trim()) &&
                        r.Cells[2].Value.ToString().Equals(txtST_No.Text.Trim()) &&
                        r.Cells[3].Value.ToString().Equals(txtSUPPL_No.Text.Trim()) &&
                        r.Cells[4].Value.ToString().Equals(txtART_No.Text.Trim()) &&
                        r.Cells[5].Value.ToString().Equals(txtDELI_QTY.Text.Trim()) &&
                        r.Cells[6].Value.ToString().Equals(txtPackage.Text.Trim()))
                    {
                        r.Selected = true;
                        var p = Picking.Objects.FirstOrDefault(x => x.PIK_No == int.Parse(r.Cells[0].Value.ToString()));
                        p.Status = true;
                        p.Update(true);
                        break;
                    }
                    else
                    {
                        MessageBox.Show("Items not found");
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
